package servlets;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SomeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String name = req.getParameter("name");
        System.out.println("name ===="+name);
        String age = req.getParameter("age");
        System.out.println("age==="+age);

        //向请求中放入属性
        req.setAttribute("name","中山大学");
        req.setAttribute("address","北京");

        //删除属性
        req.removeAttribute("address");


        //将请求转发给OtherServlet
        req.getRequestDispatcher("/other").forward(req,resp);


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        doGet(req,resp);
    }
}
